package com.example.module_service.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.lib_common.view.entity.DeviceDetailEntity
import com.example.module_service.databinding.ItemDeviceDetailBinding

class ParkDetailAdapter(private val data:MutableList<DeviceDetailEntity>):RecyclerView.Adapter<ParkDetailAdapter.DeviceItemViewHolder>() {

    inner class DeviceItemViewHolder(val itemDataBinding:ItemDeviceDetailBinding):RecyclerView.ViewHolder(itemDataBinding.root)

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ParkDetailAdapter.DeviceItemViewHolder {
        return DeviceItemViewHolder(ItemDeviceDetailBinding.inflate(LayoutInflater.from(parent.context),parent,false))
    }

    override fun onBindViewHolder(holder: ParkDetailAdapter.DeviceItemViewHolder, position: Int) {
    // 添加边界检查，防止数组越界
    if (position < 0 || position >= data.size) {
        return
    }

    val deviceDetailEntity = data[position]

    holder.itemDataBinding.run {
        entity = deviceDetailEntity

        // 动态计算进度并设置（示例：当前进度=position+1，总进度=3）
        val current = position + 1
        val total = 3
        progressText.text = "$current/$total"

        executePendingBindings()
    }
}


    override fun getItemCount(): Int {
        return data.size
    }


}





























